home *** CD-ROM | disk | FTP | other *** search
Text File | 2004-09-30 | 50.4 KB | 2,036 lines |
- <![CDATA[
- // LOOKUP.JS code BEGIN //at
- var gsExt = ".asp";
- var gaMapLang2SubNode = {'cpp' : 'iface', 'vb' : 'object'};
- var gaMapScope = {'cpp' : '::', 'vb' : '.'};
- var gaMapAttr = {'cpp' : 'iid'}; // allows the author to resolve an ambiguous reference to a shared member
- var gaMapAuto = {'cpp' : 'autoiid'}; // pointing to a shared topic we need to auto-resolve since the links differs depending on context
- var gaMapPNRN = {'rn' : 'runtime name', 'pn' : 'persistent name', 'name' : 'name'};
- var gaDLangMap = {'self' : 'devlang', 'ext' : 'dlang'}; // handle name difference: metadata/devlang vs. targ/dlang
- var aFlagAttrMap = {'cpp' : 'name', 'scr' : 'value', 'vb' : 'name'}; // map devlang to appropriate attribute in a flag
-
- // List of regular expressions for URLs that are known to be Microsoft sites
- var gaMSSiteREs = [ /microsoft\.com/i, /msn\.com/i, /gotdotnet\.com/i, /biztalk\.org/i, /bcentral\.com/i, /zone\.com/i ];
-
- // BUGBUG: Hardcoded extension map.
- var gaExtMap = {'asp' : 'htm'};
-
- var NODE_TEXT = 3;
-
- // simple source object; use an instance in place of an xref node when performing a lookup
- function CSimpleSrc(sRID, sCurLang)
- {
- this.rid = sRID;
- this.devlang = sCurLang;
- }
-
- // sets a flag indicating the object is a self reference
- CSimpleSrc.prototype.SetSelf = function(b)
- {
- this.self = b;
- }
-
- CSimpleSrc.prototype.IsSelfReference = function()
- {
- return (this.self ? true : false);
- }
-
- /////////////////////////////////////////////////////////////
-
- // encapsulates an a cached target node
- function CCacheItem(oTNode, iRefCount)
- {
- Node2Object(oTNode, this, "_");
-
- this._targetNode = oTNode;
- this._cRefs = iRefCount; // number of references to this target
- }
-
- /////////////////////////////////////////////////////////////
-
- function CLookup(oCtx)
- {
- this._oCtx = oCtx;
- this._error = "";
- this._fBadDataSrc = false;
- this._cache = new Array();
- this._aTLAs = new Array(); //at
- this._sTLA = ""; //at
- this._bTLACap = false; //at
- this._bTLAPlural = false; //at
- this._oAcronym = null; //at
- }
-
- CLookup.prototype.ClearError = function()
- {
- this._error = "";
- }
-
- // Attempt to pull the cached item from the local hash, or cache it
- CLookup.prototype.RetrieveCachedItem = function(sRID, bNoIncRefs)
- {
- var oCacheItem = this._cache[sRID];
- if (oCacheItem)
- {
- if (!bNoIncRefs)
- {
- oCacheItem._cRefs++
- }
- }
- else
- {
- oCacheItem = this.CacheItem(sRID, bNoIncRefs);
- }
-
- return oCacheItem;
- }
-
- // Lookup the specified rid in the store.
- //at *** Rewritten for LuCache.
- CLookup.prototype.RetrieveTarget = function(sRID)
- {
- var bOk = false;
- var sTargXML = null;
- var sTPath = this._oCtx._sDrive + this._oCtx.GetPathOf("targets");
- var oTNode = null;
- var oData = null;
- var bLuCache = this._oCtx.CacheLookups();
-
- oData = this.EnsureData(bLuCache);
- bLuCache = this._oCtx.CacheLookups();
-
- if (bLuCache && oData)
- {
- // Try to use the LuCache Lookup Cache.
- try
- {
- // Call LuCache to lookup the RID and get back the node-xml.
- sTargXML = oData.LookupId(sRID, sTPath);
- }
- catch(e)
- {
- this._error = "LuCache failure." + e.description;
- sTargXML = null;
- }
- if (sTargXML)
- {
- var oTDom = this._oCtx._oTDom;
-
- // Now use "mini-dom" node to load node-xml and get a node.
- oTDom.async = false;
- oTDom.loadXML(sTargXML);
- oTNode = oTDom.documentElement;
- if (oTNode)
- bOk = true;
- else
- this._error = "cannot load target node.";
- }
- else
- this._error = "rid not found (" + sRID + ").";
- }
- else
- {
- // Try to use a loaded DOM for lookups.
- if (bLuCache && !oData)
- oData = this.EnsureData(false);
- if (oData)
- {
- // oTNode = oData.selectSingleNode("id('" + sRID + "')");
- // Use faster nodeFromID.
- oTNode = oData.nodeFromID(sRID);
- if (oTNode)
- bOk = true;
- else
- this._error = "rid not found (" + sRID + ").";
- }
- else
- this._error = "cannot create access to targets.";
- }
-
- if (!bOk)
- oTNode = null;
-
- return oTNode;
- }
-
- // Get topicinfo node from topinfo.xml. //at
- CLookup.prototype.RetrieveTopicInfo = function(sID)
- {
- var bOk = false;
- var sTIXML = null;
- var sTIPath = this._oCtx._sDrive + this._oCtx.GetPathOf("topinfo");
- var oTINode = null;
- var oData = null;
- var bLuCache = this._oCtx.CacheLookups();
-
- oData = this.EnsureTIData(bLuCache);
- bLuCache = this._oCtx.CacheLookups();
-
- if (bLuCache && oData)
- {
- // Try to use the LuCache Lookup Cache.
- try
- {
- // Call LuCache to lookup the RID and get back the node-xml.
- sTIXML = oData.LookupId(sID, sTIPath);
- if (!sTIXML)
- this._error = "id not found (" + sID + ").";
- }
- catch(e)
- {
- this._error = "LuCache failure. " + e.description;
- sTIXML = null;
- }
- if (sTIXML)
- {
- var oTIDom = this._oCtx._oTDom;
-
- // Now use "mini-dom" node to load node-xml and get a node.
- oTIDom.async = false;
- oTIDom.loadXML(sTIXML);
- oTINode = oTIDom.documentElement;
- if (oTINode)
- bOk = true;
- else
- this._error = "cannot load topic info node.";
- }
- }
- else
- {
- // Try to use a loaded DOM for lookups.
- if (bLuCache && !oData)
- oData = this.EnsureTIData(false);
- if (oData)
- {
- // oTNode = oData.selectSingleNode("id('" + sID + "')");
- // Use faster nodeFromID.
- oTINode = oData.nodeFromID(sID);
- if (oTINode)
- bOk = true;
- else
- this._error = "id not found (" + sID + ").";
- }
- else
- {
- if (!this._error)
- this._error = "cannot create access to topic info.";
- }
- }
-
- if (!bOk)
- oTINode = null;
-
- return oTINode;
- }
-
- // Get acronym node (ie, using TLA rid) from acronyms.xml. //at
- CLookup.prototype.RetrieveAcronym = function(sID)
- {
- var bOk = false;
- var sAcXML = null;
- var sAcPath = this._oCtx._sDrive + this._oCtx.GetPathOf("acronyms");
- var sAcDtdPath = this._oCtx._sDrive + this._oCtx.GetPathOf("acronymsdtd");
- var oAcNode = null;
- var oData = null;
- var bLuCache = this._oCtx.CacheLookups();
-
- oData = this.EnsureAcData(bLuCache);
- bLuCache = this._oCtx.CacheLookups();
-
- if (bLuCache && oData)
- {
- // Try to use the LuCache Lookup Cache.
- try
- {
- // Call LuCache to lookup the RID and get back the node-xml.
- sAcXML = oData.LookupId(sID, sAcPath);
- if (!sAcXML)
- this._error = "id not found (" + sID + ").";
- }
- catch(e)
- {
- this._error = "LuCache failure. " + e.description;
- sAcXML = null;
- }
- if (sAcXML)
- {
- var oAcDom = this._oCtx._oTDom;
- var sXML = '<!DOCTYPE acronym SYSTEM "'+sAcDtdPath+'" []>'+sAcXML;
-
- // Now use "mini-dom" node to load node-xml and get a node.
- oAcDom.async = false;
- oAcDom.loadXML(sXML);
- oAcNode = oAcDom.documentElement;
- if (oAcNode)
- bOk = true;
- else
- this._error = "cannot load acronym node.";
- }
- }
- else
- {
- // Try to use a loaded DOM for lookups.
- if (bLuCache && !oData)
- oData = this.EnsureAcData(false);
- if (oData)
- {
- // oAcNode = oData.selectSingleNode("id('" + sID + "')");
- // oAcNode = oData.selectSingleNode("/acroot/inetsdk:acronyms/acronym[@id='"+sID+"']");
- // Use faster nodeFromID.
- oAcNode = oData.nodeFromID(sID);
- if (oAcNode)
- bOk = true;
- else
- this._error = "id not found (" + sID + ").";
- }
- else
- {
- if (!this._error)
- this._error = "cannot create access to acronyms.";
- }
- }
-
- if (oAcNode && oAcNode.getAttribute("deprecated"))
- bOk = false;
-
- if (!bOk)
- oAcNode = null;
-
- return oAcNode;
- }
-
- // Resets firsttime status for all TLAs encountered so far in the
- // page transformation. Use with care. //at
- CLookup.prototype.ResetTLA = function()
- {
- var i = 0;
-
- if (this._aTLAs)
- {
- delete this._aTLAs;
- this._aTLAs = new Array(); //at
- }
-
- return false;
- }
-
- // Determine if the authored TLA is in acronyms.xml.
- // Called directly from XSL. //at
- CLookup.prototype.IsTLA = function(oTLA)
- {
- var bYes = false;
- var sRid = null;
- var oAc = null;
- var sVal = "";
-
- this._sTLA = "";
- this._bTLACap = false;
- this._bTLAPlural = false;
- this._oAcronym = null;
-
- if (oTLA)
- {
- sRid = oTLA.getAttribute("rid");
- if (sRid)
- {
- oAc = this.RetrieveAcronym(sRid);
- if (oAc)
- {
- sVal = oTLA.getAttribute("initcap");
- if (sVal)
- this._bTLACap = true;
-
- sVal = oTLA.getAttribute("plural");
- if (sVal)
- this._bTLAPlural = true;
-
- this._oAcronym = oAc;
- bYes = true;
- }
- }
- }
-
- return bYes;
- }
-
- // In the current document, determine if this node is the first
- // TLA using its associated ID (rid). Use associative array to
- // remember the TLA Rids encountered. //at
- CLookup.prototype.IsFirstTLA = function(sRid)
- {
- var bYes = false;
- var bFound = false;
-
- if (sRid)
- {
- bFound = this._aTLAs[sRid];
- if (!bFound)
- {
- this._aTLAs[sRid] = true;
- bYes = true;
- }
- }
-
- return bYes;
- }
-
- // Workhorse internal function to build the TLA substitution
- // string when nested TLA strings are being appended.
- // Note the indirect recursive call relation between this
- // function and MakeTLA. //at
- CLookup.prototype.NestTLA = function(oAcNode)
- {
- var bOk = false;
- var oAcNested = null;
- var aNested = null;
- var oNested = null;
- var sRidNested = "";
- var sText = "";
- var sChar = "";
- var i = 0;
-
- if (oAcNode)
- {
- aNested = oAcNode.selectNodes("tla");
- if (aNested && aNested.length>0)
- {
- for(i=0; i<aNested.length; i++)
- {
- oNested = aNested[i];
- if (oNested)
- {
- sRidNested = oNested.getAttribute("rid");
- if (sRidNested)
- {
- oAcNested = this.RetrieveAcronym(sRidNested);
- bOk = this.MakeTLA(oAcNested);
- }
- }
- }
-
- sText = oAcNode.text;
- sChar = sText.substr(0,1);
- sChar = sChar.toLowerCase();
- switch (sChar)
- {
- case ".":
- sText = sText.toLowerCase();
- if (sText == ".net")
- this._sTLA += " "+oAcNode.text;
- else
- this._sTLA += oAcNode.text;
- break;
- case " ":
- case ",":
- case ":":
- case ";":
- this._sTLA += oAcNode.text;
- break;
- default:
- this._sTLA += " "+oAcNode.text;
- break;
- }
- }
- else
- this._sTLA += oAcNode.text;
- }
-
- return bOk;
- }
-
- // Workhorse internal recursive function that builds the substitution
- // string for a TLA. It determines if the Acronym node (oAc) should
- // be expanded to its primary or secondary representation.
- // According to MSTE, the first instance of a trademark (TM) or
- // registered trademark (R) name should include the trademark marking.
- // Editorially, this should also mean that the first use of a
- // product name within a topic should be referenced by a TLA that
- // has the proper marking. Subsequent instances of the trademarked
- // names within the same topic should not show the trademark
- // marking. Note the indirect recursive call relation between this
- // function and NestTLA. //at
- CLookup.prototype.MakeTLA = function(oAc)
- {
- var bOk = false;
- var bFirst = true;
- var sRid = "";
- var oPrimary = null;
- var oSecondary = null;
-
- if (oAc)
- {
- oSecondary = oAc.selectSingleNode("secondary");
- oPrimary = oAc.selectSingleNode("primary");
- sRid = oAc.getAttribute("id");
- bFirst = this.IsFirstTLA(sRid);
- if (bFirst)
- bOk = this.NestTLA(oPrimary);
- else
- {
- if (oSecondary)
- bOk = this.NestTLA(oSecondary);
- else
- bOk = this.NestTLA(oPrimary);
- }
- }
-
- return bOk;
- }
-
- //at Make Plural TLA.
- CLookup.prototype.MakeTLAP = function(oAc)
- {
- var bOk = false;
- var bFirst = true;
- var sRid = "";
- var oPrimary = null;
- var oSecondary = null;
-
- if (oAc)
- {
- oSecondary = oAc.selectSingleNode("secondaryp");
- oPrimary = oAc.selectSingleNode("primaryp");
- sRid = oAc.getAttribute("id");
- bFirst = this.IsFirstTLA(sRid);
- if (bFirst)
- this.NestTLA(oPrimary);
- else
- {
- if (oSecondary)
- this.NestTLA(oSecondary);
- else
- this.NestTLA(oPrimary);
- }
- bOk = true;
- }
-
- return bOk;
- }
-
- // Just return the TLA's substitution string.
- // Must be called immediately after IsTLA has been called.
- // Called internally or directly from XSL. //at
- CLookup.prototype.GetTLA = function(oAcronym)
- {
- var sChar = "";
- var sRest = "";
- var sRet = "";
- var sTLA = "";
- var nLen = 0;
- var oAc = null;
- var bPlDone = false;
-
- if (oAcronym)
- {
- this._sTLA = "";
- oAc = oAcronym;
- }
- else
- oAc = this._oAcronym;
-
- if (this._bTLAPlural && oAc.selectSingleNode("primaryp"))
- bPlDone = this.MakeTLAP(oAc);
- else
- this.MakeTLA(oAc);
-
- if (this._bTLACap)
- {
- sTLA = this._sTLA;
- sChar = sTLA.substr(0,1);
- sRest = sTLA.substr(1);
- this._sTLA = sChar.toUpperCase() + sRest;
- }
-
- if (!bPlDone && this._bTLAPlural)
- {
- sTLA = this._sTLA;
- nLen = sTLA.length;
- sChar = sTLA.substr(nLen-1,1);
- sChar = sChar.toLowerCase();
- switch (sChar)
- {
- case "x":
- case "s":
- sRest = "es";
- break;
- default:
- sRest = "s";
- break;
- }
- this._sTLA = sTLA + sRest;
- }
-
- return this._sTLA;
- }
-
- // Find TLA and return its substitution string.
- // Called directly from XSL. //at
- CLookup.prototype.TLA = function(sRid)
- {
- var sTLA = "";
- var oAc = null;
-
- this._sTLA = "";
- this._oAcronym = null;
- this._bTLACap = false;
- this._bTLAPlural = false;
-
- if (sRid)
- {
- oAc = this.RetrieveAcronym(sRid);
- if (oAc)
- {
- this._oAcronym = oAc;
- sTLA = this.GetTLA();
- }
- }
-
- return sTLA;
- }
-
-
- // convert the attribs of the target node to properties of a
- // JS object and store the target node in hash.
- CLookup.prototype.CacheItem = function(sRID, bNoIncRefs)
- {
- var oTNode;
- if (!(oTNode = this.RetrieveTarget(sRID)))
- {
- return null;
- }
-
- return new CCacheItem(oTNode, (bNoIncRefs ? 0 : 1));
- //return (this._cache[sRID] = new CCacheItem(oTNode, (bNoIncRefs ? 0 : 1)));
- }
-
- // given an id, lookup the corresponding target
- // sRID - the ID of the desired topic (no default)
- // oDest - where to put the results of the lookup (no default)
- // bNoIncRefs - whether or not this lookup should count toward a reference (default is false)
- // sCurLang - the desired devlang for the lookup (default is the global devlang)
- // sOID - disambiguate the desired interface or object id (depending on the devlang) of the member (no default)
- // if "auto" is specified, the primary/active interface of the current topic is used
- CLookup.prototype.LookupByRID = function(sRID, oDest, bNoIncRefs, sCurLang, sOID)
- {
- if (!sCurLang)
- {
- sCurLang = this._oCtx._devlang;
- }
-
- var oSrc = new CSimpleSrc(sRID, sCurLang);
- if (sOID)
- {
- this.AddOID(oSrc, sOID);
- }
-
- return this.Lookup(oSrc, oDest, bNoIncRefs);
- }
-
- // adorn the source object with the requested iid or auto qualifier
- // this helps to resolve otherwise ambiguous xrefs
- CLookup.prototype.AddOID = function(oSrc, sOID)
- {
- var sAttr = null, sCurLang = oSrc.devlang;
- if (sOID == 'auto')
- {
- if (sAttr = gaMapAuto[sCurLang])
- {
- oSrc[sAttr] = 1;
- }
- }
- else if (sAttr = gaMapAttr[sCurLang])
- {
- oSrc[sAttr] = sOID;
- }
- }
-
- // Lookup the target referenced by oNode.
- // Assumption here is that oNode is an XML DOM node that exposes a @rid.
- // CONSIDER: Support sKey parameter so that topic id can be
- // identified by some attr other than @rid.
- CLookup.prototype.LookupByNode = function(oNode, oDest, bNoIncRefs, sOID)
- {
- if (!oNode)
- {
- this._error = "null node passed to LookupByNode";
- return false;
- }
-
- var sRID = oNode.getAttribute("rid");
- if (!sRID)
- {
- this._error = "@rid not found on " + oNode.nodeName;
- return false;
- }
-
- var oObj = Node2Object(oNode);
- if (!oObj)
- {
- return false;
- }
-
- if (!oObj.devlang)
- {
- oObj.devlang = this._oCtx._devlang;
- }
-
- // only attach the source node if it's an xref
- if ("xref" == oNode.nodeName.toLowerCase())
- {
- oObj._srcNode = oNode;
- }
- else
- {
- // this param will never be passed in the typical xref case
- // it will likely be passed in the iface/imembers case
- if (sOID)
- {
- this.AddOID(oObj, sOID);
- }
- }
-
- //special processing for xrefs with qualify='0' attribute
- //added by petertay for GDI+ - note that this a total hack, but it would take too long to implement properly
- if("xref" == oNode.nodeName.toLowerCase())
- {
- //check current xref for qualify attribute
- if(oNode.getAttribute("qualify")=="0")
- {
- //it's okay to go ahead and do the lookup
- var bReturn = this.Lookup(oObj, oDest, bNoIncRefs);
- var compString = oDest._caption;
- var _index = compString.indexOf("::");
- if (_index == "-1")
- {
- //this is an error, there is no scope operator in the name attribute on the targ
- this._error = "qualify attribute used with non-qualified target name - check name in targets2.xml";
- return false;
- }
- else
- {
- oDest._caption = compString.substring(_index+2,compString.length);
- }
- return bReturn;
- }
- //no qualify attribute on the xref, continue normally
- else
- {
- return this.Lookup(oObj, oDest, bNoIncRefs);
- }
- }
- //this was not an xref, go ahead and do the lookup as requested
- else
- {
- return this.Lookup(oObj, oDest, bNoIncRefs);
- }
-
- }
-
- // look for a target by name. This is slow (!!!) because
- // topics are not indexed by name.
- //at *** Rewritten for LuCache backend.
- // sName - the @name of the topic
- // oDest - js object used to store results
- // sCriteria - optional string used to help refine the query
- CLookup.prototype.LookUpByName = function(sName, oDest, sCriteria)
- {
- var bOk = false;
- var sTargXML = null;
- var sTPath = this._oCtx._sDrive + this._oCtx.GetPathOf("targets");
- var oTNodes = null;
- var oTNode = null;
- var oData = null;
- var bLuCache = this._oCtx.CacheLookups();
-
- oData = this.EnsureData(bLuCache);
- bLuCache = this._oCtx.CacheLookups();
-
- oDest.Init();
-
- if (sName)
- {
- oDest.SetCaption(sName);
-
- sCriteria = NormalizeCriteria(sCriteria);
-
- if (bLuCache && oData)
- {
- // Try to use the LuCache Lookup Cache.
- try
- {
- // Call LuCache to lookup the name and get back the node-xml.
- sTargXML = oData.LookupField(sName, "name", sTPath, sCriteria);
- }
- catch(e)
- {
- sTargXML = null;
- }
- if (sTargXML)
- {
- var oTDom = this._oCtx._oTDom;
-
- // Now use mini-dom node to load node-xml and get a node.
- oTDom.async = false;
- oTDom.loadXML(sTargXML);
- oTNode = oTDom.documentElement;
- if (oTNode)
- bOk = true;
- else
- this._error = "cannot load node xml.";
- }
- else
- this._error = "cannot locate " + sName;
- }
- else
- {
- // Try to use a loaded DOM for lookups.
- if (bLuCache && !oData)
- oData = this.EnsureData(false);
- if (oData)
- {
- oTNodes = oData.selectNodes("/inetsdk:targets/targ[@name='" + sName + "']" + sCriteria);
- if (oTNodes && oTNodes.length)
- {
- // BUGBUG: If we get back more than one, how do we disambiguate
- // beyond sCriteria?
- oTNode = oTNodes[0];
- if (oTNode)
- bOk = true;
- else
- this._error = "cannot locate " + sName;
- }
- }
- else
- this._error = "cannot create access to targets.";
- }
- }
-
- if (bOk)
- {
- var sRID = oTNode.getAttribute("id");
- if (sRID)
- {
- var oSrc = new CSimpleSrc(sRID, this._oCtx._devlang);
- var oCacheItem = this.RetrieveCachedItem(sRID, true);
- if (oCacheItem)
- bOk = this.BuildHREF(oSrc, oDest, oCacheItem);
- else
- bOk = false;
- }
- else
- {
- // wasted check. should never happen acc. DTD
- this._error = "missing @rid";
- bOk = false;
- }
- }
-
- return bOk;
- }
-
- CLookup.prototype.BuildExtendedId = function(oSrc, oDest, oCacheItem){
- var result = "";
- var sDevLang = "";
-
- dp = oDest._ionodes.context.selectSingleNode(oDest._ionodes.expr); // this is the deployment used.
-
- dp.getAttribute("hack") ? sDevLang = "scr" : sDevLang = dp.parentNode.getAttribute("value");
- if (sDevLang == "none") sDevLang = "";
-
- // must make the extended id. this id is derived from information about the link.
- if(sDevLang == 'cpp' && dp.getAttribute("rid")){
- result = result + dp.getAttribute("rid");
- }
- result = result + oSrc.rid;
-
- if (sDevLang != "") {
- result = result + "_" + sDevLang;
- }
-
- if(result){
- oDest._extendedRid = result;
- }
-
- // <META NAME="MS-HAID"><xsl:attribute name="CONTENT">
- //<xsl:choose>
- //<xsl:when test=".[/inetsdk:topic/metadata/applies/iface $and$ &var_devlang;='cpp']">
- // <xsl:choose>
- // <xsl:when test="/inetsdk:topic/metadata/applies/iface[@primary]"><xsl:value-of select="/inetsdk:topic/metadata/applies/iface[@primary]/@rid"/></xsl:when>
- // <xsl:otherwise><xsl:value-of select="/inetsdk:topic/metadata/applies/iface/@rid"/></xsl:otherwise>
- // </xsl:choose>
- //</xsl:when>
- //<xsl:when test=".[/inetsdk:topic/metadata/applies/object $and$ &var_devlang;='vb']">
- // <xsl:choose>
- // <xsl:when test="/inetsdk:topic/metadata/applies/object[@primary]"><xsl:value-of select="/inetsdk:topic/metadata/applies/object[@primary]/@rid"/></xsl:when>
- // <xsl:otherwise><xsl:value-of select="/inetsdk:topic/metadata/applies/object/@rid"/></xsl:otherwise>
- // </xsl:choose>
- //</xsl:when>
- ///</xsl:choose><xsl:value-of select="/inetsdk:topic/metadata/@id"/>&var_suffix;</xsl:attribute></META>
-
- return result;
- }
-
- // use the metadata to fake a lookup
- // metadata is *mostly* polymorphic with a target node. No hrefs in metadata
- // This replaces GetMetaData
- // oNode - represents an xref when called from xref.xsl. Can be null
- // oDest - represents the destination object in which to cache results
- CLookup.prototype.LookupLocal = function(oNode, oDest)
- {
- var oCtx = this._oCtx;
- var oDoc = oCtx.GetDocument();
- if (!oDoc)
- {
- this._error = "document reference unavailable in LookupLocal";
- return false;
- }
-
- var oMDNode = oDoc.selectSingleNode('/inetsdk:topic/metadata');
- if (!oMDNode)
- {
- this._error = 'unable to locate metadata';
- return false;
- }
-
- var oSrcObj = null;
- if (oNode)
- {
- oSrcObj = Node2Object(oNode);
- if (!oSrcObj)
- {
- return false;
- }
-
- if (!oSrcObj.devlang)
- {
- oSrcObj.devlang = oCtx.GetDevLang();
- }
- }
- else
- {
- // no xref node was passed in, so cook up up
- oSrcObj = new CSimpleSrc(oMDNode.getAttribute("id"), oCtx.GetDevLang());
- }
-
- oSrcObj.self = true; // this is a self-reference
-
- oDest.Init();
-
- var oCacheItem = new CCacheItem(oMDNode, 0);
-
- oDest.SetItem(oSrcObj.rid, oCacheItem);
-
- // only attach the source node if it's an xref
- if ("xref" == oNode.nodeName.toLowerCase())
- {
- oSrcObj._srcNode = oNode;
- }
-
- if (!this.ExtractCaption(oSrcObj, oDest, oCacheItem))
- {
- return false;
- }
-
- return true;
- }
-
- // Lookup the xref referenced by oSrc.
- // bNoIncRefs - if true, the reference count for the target is not incremented
- CLookup.prototype.Lookup = function(oSrc, oDest, bNoIncRefs)
- {
- if (!oDest)
- {
- this._error = "Lookup: null destination data object";
- return false;
- }
-
- if (!oSrc)
- {
- this._error = "Lookup: null source data object";
- return false;
- }
-
- if (this._fBadDataSrc)
- {
- return false;
- }
-
- this.ClearError();
-
- oDest.Init(); // clear out volatile data from the destination data object
-
- var sRID = oSrc.rid;
- if (!sRID)
- {
- this._error = "@rid missing " + (oSrc._nodeName ? " on " + oSrc._nodeName : "");
- return false;
- }
-
- var oCacheItem = this.RetrieveCachedItem(sRID, bNoIncRefs);
- if (!oCacheItem)
- {
- return false;
- }
-
- oDest.SetItem(sRID, oCacheItem);
-
- if (!oSrc.devlang)
- {
- oSrc.devlang = this._oCtx._devlang;
- }
-
- if (!this.ExtractCaption(oSrc, oDest, oCacheItem))
- {
- return false;
- }
-
- if (!this.BuildHREF(oSrc, oDest, oCacheItem))
- {
- return false;
- }
-
- if (!this.BuildExtendedId(oSrc, oDest, oCacheItem)){
- return false;
- }
-
- return true;
- }
-
- CLookup.prototype.HasOverridingCaption = function(oSrc)
- {
- var oRequest;
- return (((oRequest = oSrc._srcNode) && oRequest.firstChild) ? true : false);
- }
-
- CLookup.prototype.GetOverridingCaption = function(oSrc)
- {
- var sCaption = "";
- var oTLA = null;
- var oRequest = oSrc._srcNode;
-
- if (oRequest)
- {
- //at: Add support for nested TLA in the overriding caption.
- //Assumption is that if an xref contains a tla, the tla precedes any text
- oTLA = oRequest.selectSingleNode("tla");
- if (oTLA)
- {
- if (this.IsTLA(oTLA))
- sCaption = this.GetTLA();
- if (oRequest.text)
- sCaption += " ";
- }
-
- if (oRequest.text)
- {
- sCaption += oRequest.text;
- }
- }
-
- return sCaption;
- }
-
- /*
- Extract the caption from the data source
-
- oSrc - js object representing the source data requesting the link
- oCacheItem - js object representing the target node representing the link
- */
- CLookup.prototype.ExtractCaption = function(oSrc, oDest, oCacheItem)
- {
- // BUGBUG: Neglects the possibility of markup descending from the xref (e.g. img)
- var oTNode = oCacheItem._targetNode;
- var sTPN = oCacheItem._pn;
- var bObj = (oSrc._nodeName && ("object" == oSrc._nodeName.toLowerCase()));
- var oDLNode;
-
- // first check if author has provided custom innerText for link
- // requires that the source XML node be attached to the source object
- if (this.HasOverridingCaption(oSrc))
- {
- oDest.SetCaption(this.GetOverridingCaption(oSrc));
- return true;
- }
-
- // Look for persistent name in targ
- // if: xref rid="..." type="pn"
- if (oSrc.type && ("pn" == oSrc.type))
- {
- if (!sTPN)
- {
- this._error = "target does not specify requested @pn.";
- return false;
- }
- else
- {
- oDest.SetCaption(sTPN);
- }
- }
- else
- {
- var sSubQuery;
-
- //markda: special processing if we are using targets V2.
- if ( this._oCtx.UseTargetsV2() && !oSrc.self )
- {
- sSubQuery = "/dp_info[@name]";
- }
- else
- {
- sSubQuery = "[@name]";
- }
-
- oDLNode = oTNode.selectSingleNode(gaDLangMap[(oSrc.self ? 'self' : 'ext')] + "[@value='" + oSrc.devlang + "']" + sSubQuery);
- if (oDLNode)
- {
- //markda: if there's a devlang-specific caption, use it.
- oDest.SetCaption(oDLNode.getAttribute("name"));
- }
- else
- {
- //at: Else if we're processing an object (eg, xrefs in AppliesTo),
- //at: then use the persistent name if the targ has one;
- //at: otherwise use the normal name. Note that this logic
- //at: assumes that pn has the correct upper/lower case for
- //at: items like INPUT type=button.
- if (bObj && sTPN)
- oDest.SetCaption(sTPN);
- else
- oDest.SetCaption(oCacheItem._name);
- }
- } //markda
-
- // only attempt to extend the caption if the href is not at the targ level.
- // href on a targ indicates language neutrality or legacy HTM/ASP.
- if (!oCacheItem._href)
- {
- var sPageType = oCacheItem._type, sDevLang = oSrc.devlang;
-
- if ((oSrc.type != 'pn') && (sDevLang == "cpp") && (sPageType == "method" || sPageType == "property" || sPageType == "collection" || sPageType == "event"))
- {
- // Look for an iface/object prefix
- if (!this.GetExtendedCaption(oSrc, oDest, oCacheItem))
- {
- return false;
- }
- }
- }
-
- return true;
- }
-
- CLookup.prototype.GetExtendedCaption = function(oSrc, oDest, oCacheItem)
- {
- // BUGBUG: if this is a property, prepend the put/get if C++??
- var oNodes = null;
- if (!(oNodes = this.EnsureIONodes(oSrc, oDest, oCacheItem)))
- {
- return false;
- }
- else if (oNodes.length == 1)
- {
- return this.GatherTargetData(oSrc, oDest, oNodes[0]);
- }
- else // (oNodes.length > 1)
- {
- if (oSrc.self) // the @primary check only works in the self-reference case
- {
- var sIOQuery = "applies/" + gaMapLang2SubNode[oSrc.devlang] + "[@primary]";
- var oNode = oCacheItem._targetNode.selectSingleNode(sIOQuery);
- if (oNode)
- {
- return this.GatherTargetData(oSrc, oDest, oNode);
- }
- else
- {
- this.GatherTargetData(oSrc, oDest, oNodes[0]);
- return true;
- }
- }
- else
- {
- this._error = "ambiguous xref; must specify @iid, @oid, or @primary.";
- return false;
- }
- }
-
- }
-
- CLookup.prototype.GatherTargetData = function(oSrc, oDest, oNode)
- {
- var sIOCaption = oNode.getAttribute("name");
- if (sIOCaption)
- {
- oDest.SetCaption(sIOCaption);
- }
- else
- {
- //markda: attribute optional for targets V2
- var sRID;
- if ( sRID = oNode.getAttribute("rid") )
- {
- //markda: end
- // The following code executes when the target node (oNode) is actually part of the topic/metadata (self-reference case)
- // In that case we need to do a lookup because the redundant data is not stored there
- var sRID = oNode.getAttribute("rid");
- var oIONode = this.RetrieveTarget(sRID);
- if (!oIONode)
- {
- // this._error = gaMapLang2SubNode[oSrc.devlang] + "'" + sRID + "' not found."
- return false;
- }
-
- // pre-pend the appropriate scope operator
- // @petertay UNLESS there is a qualify="0" attribute on the xref
- if(oSrc.qualify=="0")
- {
- oDest.SetCaption(oDest.GetCaption());
- }
- else
- {
- oDest.SetCaption(oIONode.getAttribute("name") + gaMapScope[oSrc.devlang] + oDest.GetCaption());
- }
- }
- //markda: if using targets V2, use targ[@name] if no dp_info[@name]
- else
- {
- if ( this._oCtx.UseTargetsV2()
- && (sIOCaption = oNode.parentNode.parentNode.getAttribute("name")) )
- {
- oDest.SetCaption(sIOCaption);
- }
- }
- }
- //markda: end
-
- return true;
- }
-
- // Build a query to drill into the target, and return the collection of nodes that qualify
- CLookup.prototype.EnsureIONodes = function(oSrc, oDest, oCacheItem)
- {
- // self base query: applies/iface[@rid=''] or applies/object[@rid='']
- // extern base query: dlang[@value='cpp']/dp_iface or dlang[@value='vb']/dp_object
- //markda: for targets V2: dlang[@value='cpp']/dp_info or dlang[@value='vb']/dp_info
-
- var sDevLang = oSrc.devlang;
-
- //markda: with targets V2, all devlangs have subnodes
- if ( ! this._oCtx.UseTargetsV2() )
- {
- //markda: end
- // no need to check for iface/object for this devlang
- if (typeof(gaMapLang2SubNode[sDevLang]) == 'undefined')
- {
- this._error = "devlang '" + sDevLang + "' doesn't support subnodes.";
- return null;
- }
- } //markda
-
- if (oDest._ionodes)
- {
- return oDest._ionodes;
- }
-
- var sIOQuery;
-
- if (oSrc.self)
- {
- sIOQuery = "applies/" + gaMapLang2SubNode[sDevLang];
- }
- else
- {
- //markda: determine if we are using targets V1 or V2
- if ( this._oCtx.UseTargetsV2() )
- {
- if ( sDevLang == "" )
- sDevLang = "none";
- sIOQuery = "dlang[@value='" + sDevLang + "']/dp_info";
- }
- else //markda: end
- sIOQuery = "dlang[@value='" + sDevLang + "']/dp_" + gaMapLang2SubNode[sDevLang];
- }
-
- // check if the author has specified an @iid or @oid on the xref
- if (typeof(gaMapAttr[sDevLang]) != 'undefined' && oSrc)
- {
- // attempt to qualify the query so as to avoid an ambiguous xref
-
- var sAttr, sVal, sIORID = null;
- // use the @iid or @oid if one has been specified
- if ( (sAttr = gaMapAttr[sDevLang]) && (sVal = oSrc[sAttr]) )
- {
- sIORID = sVal;
- }
- // otherwise attempt to autoresolve if the author gave us permission
- else if ( (sAttr = gaMapAuto[sDevLang]) && oSrc[sAttr] )
- {
-
- var oIFaces;
- var sPageType = GetPageType(); // get the type of the current doc
- if (sPageType && (sPageType == "iface"))
- {
- var oIFaceID = ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@id");
- if (!oIFaceID)
- {
- this._error = "interface page doesn't specify an id";
- return false;
- }
- else
- {
- sIORID = oIFaceID.value;
- }
- }
- // use the primary iid of the current topic
- else if ( (oIFaces = ownerDocument.selectNodes("/inetsdk:topic/metadata/applies/" + gaMapLang2SubNode[sDevLang] + "[@rid $and$ @primary]") ) && oIFaces.length == 1)
- {
- sIORID = oIFaces[0].getAttribute("rid");
- }
- else if ( (oIFaces = ownerDocument.selectNodes("/inetsdk:topic/metadata/applies/" + gaMapLang2SubNode[sDevLang] + "[@rid]")) && oIFaces.length == 1)
- {
- sIORID = oIFaces[0].getAttribute("rid");
- }
- }
-
- if (sIORID)
- {
- sIOQuery += "[@rid='" + sIORID + "']";
- }
- }
-
- // query for the iface/object nodes below the target
- var oNodes = oCacheItem._targetNode.selectNodes(sIOQuery);
- if (!oNodes || !oNodes.length)
- {
- //markda: attempt to get generic target
- if ( this._oCtx.UseTargetsV2() )
- {
- oNodes = oCacheItem._targetNode.selectNodes( "dlang/dp_info" );
- if (!oNodes || !oNodes.length)
- {
- this._error = "query failure after retry! [" + sIOQuery + "]";
- return null;
- }
- }
- else
- { //markda: end
- this._error = "query failure! [" + sIOQuery + "]";
- return null;
- } //markda
- }
-
- return (oDest._ionodes = oNodes);
- }
-
- CLookup.prototype.GetError = function()
- {
- return this._error;
- }
-
- CLookup.prototype.IsType = function(o, oDest, sCompareType)
- {
- if (!this.LookupByNode(o, oDest, true))
- {
- return false;
- }
-
- var sType = oDest.GetType();
- return (sType == sCompareType ? true : false);
- }
-
- // load the data source used to perform lookups
- //at *** Rewritten for LuCache.
- CLookup.prototype.EnsureData = function(bLuCache)
- {
- var oData = null;
- var sError = "";
-
- // BUGBUG: What if object is created but data can't be loaded
- if (typeof(this._data) == 'undefined')
- {
- // Determine if LuCache is out there.
- try
- {
- oData = new ActiveXObject("LuCache.Lookup");
- }
- catch(e)
- {
- sError = "cannot instantiate LuCache. " + e.description;
- }
-
- if (bLuCache)
- {
- // Try to use the LuCache fast lookup cache.
- if (oData)
- this._data = oData;
- else
- {
- this._error = sError;
- this._oCtx.NoCacheLookups();
- }
- }
-
- if (!this._data)
- {
- // Try to use an XML DOM.
- try
- {
- this._data = new ActiveXObject("MSXML.DOMDocument");
- }
- catch(e)
- {
- this._error = "cannot instantiate MSXML. " + e.description;
- return null;
- }
-
- this._data.async = false;
- this._data.load(this._oCtx.GetPathOf("targets"));
- var oPErr = this._data.parseError;
- if (oPErr.errorCode != 0)
- {
- this._error = oPErr.url + "(" + oPErr.line + "): Targets lookup error: " + oPErr.reason.replace(/[\n\r]/g,"");
- this._fBadDataSrc = true;
- return null;
- }
- }
- }
- else if (this._fBadDataSrc)
- {
- return null;
- }
-
- //at+ Add code here to check for parse error during load of targets.xml.
- //at+ This would require a new method, ILookup::GetError.
-
- return this._data;
- }
-
- // Ensure topic info (topinfo.xml) is available for retrieval. //at
- CLookup.prototype.EnsureTIData = function(bLuCache)
- {
- var oData = null;
- var sError = "";
-
- if (typeof(this._tidata) == 'undefined')
- {
- // Determine if LuCache is out there.
- try
- {
- oData = new ActiveXObject("LuCache.Lookup");
- }
- catch(e)
- {
- sError = "cannot instantiate LuCache. " + e.description;
- }
-
- if (bLuCache)
- {
- // Try to use the LuCache fast lookup cache.
- if (oData)
- this._tidata = oData;
- else
- {
- this._error = sError;
- this._oCtx.NoCacheLookups();
- }
- }
-
- if (!this._tidata)
- {
- // Try to use an XML DOM.
- try
- {
- this._tidata = new ActiveXObject("MSXML.DOMDocument");
- }
- catch(e)
- {
- this._error = "cannot instantiate MSXML. " + e.description;
- return null;
- }
-
- this._tidata.async = false;
- this._tidata.load(this._oCtx.GetPathOf("topinfo"));
- var oPErr = this._tidata.parseError;
- if (oPErr.errorCode != 0)
- {
- this._error = oPErr.url + "(" + oPErr.line + "): Topic Info lookup error: " + oPErr.reason.replace(/[\n\r]/g,"");
- this._fBadDataSrc = true;
- return null;
- }
- }
- }
- else if (this._fBadDataSrc)
- {
- return null;
- }
-
- return this._tidata;
- }
-
- // Ensure Acronyms data (acronyms.xml) is available for retrieval. //at
- CLookup.prototype.EnsureAcData = function(bLuCache)
- {
- var oData = null;
- var sError = "";
-
- if (typeof(this._acdata) == 'undefined')
- {
- // Determine if LuCache is out there.
- try
- {
- oData = new ActiveXObject("LuCache.Lookup");
- }
- catch(e)
- {
- sError = "cannot instantiate LuCache. " + e.description;
- }
-
- if (bLuCache)
- {
- // Try to use the LuCache fast lookup cache.
- if (oData)
- this._acdata = oData;
- else
- {
- this._error = sError;
- this._oCtx.NoCacheLookups();
- }
- }
-
- if (!this._acdata)
- {
- // Try to use an XML DOM.
- try
- {
- this._acdata = new ActiveXObject("MSXML.DOMDocument");
- }
- catch(e)
- {
- this._error = "cannot instantiate MSXML. " + e.description;
- return null;
- }
-
- this._acdata.async = false;
- this._acdata.load(this._oCtx.GetPathOf("acronyms"));
- var oPErr = this._acdata.parseError;
- if (oPErr.errorCode != 0)
- {
- this._error = oPErr.url + "(" + oPErr.line + "): TLA lookup error: " + oPErr.reason.replace(/[\n\r]/g,"");
- this._fBadDataSrc = true;
- return null;
- }
- }
- }
- else if (this._fBadDataSrc)
- {
- return null;
- }
-
- return this._acdata;
- }
-
- CLookup.prototype.BuildHREF = function(oSrc, oDest, oCacheItem)
- {
- var oTNode = oCacheItem._targetNode;
- var sMedia = this._oCtx._media;
- var sChm = oTNode.getAttribute("chm");
- var sPerm = oTNode.getAttribute("perm");
- var sDelivery = oTNode.getAttribute("delivery");
- var sTargHREF = "";
- var isALink = false;
- var isHXSLink = false;
- var bHTTP = false;
-
- if(sDelivery && !sChm){
- this._error = "cannot have @delivery without @chm."
- return false;
- }
-
- if(sChm && !sPerm){
- this._error = "cannot have @chm without @perm."
- return false;
- }
-
- oDest._leave = "";
-
- oDest._hxslink = "";
- /* This section moved down (in modified form) to line 1533
- if (sMedia && sChm == "other")
- {
- switch (sMedia)
- {
- case "chm":
- // generate an ALINK if we're in CHM mode and are
- // linking to something in another CHM
- oDest._alink = oSrc.rid;
- // javascript: doesn't like ids that contain colons. Convert to "__"
- oDest._alinkproxy = oSrc.rid.replace(":","__");
- oDest.SetHREF("JavaScript:" + oDest._alinkproxy + ".Click()");
- oDest._leave = "chm";
- return true;
- break;
- case "hxs":
- //at: Assemble the Havana (Hxs) link if we're in CHM mode and are
- // linking to something in another CHM
- oDest._hxslink = '<MSHelp:link keywords="' + oSrc.rid + '" TABINDEX="0">' + oDest._caption + '</MSHelp:link>';
- oDest._leave = "chm";
- return true;
- break;
- default:
- break;
- }
- }
- */
-
- if (!this.ExtractHREF(oSrc, oDest, oCacheItem))
- {
- return false;
- }
-
- sTargHREF = oDest.GetHREF();
- bHTTP = /^http:\/\//i.test(sTargHREF);
-
- if (sMedia)
- {
- switch (sMedia)
- {
- case "chm":
- if(sPerm){
- if(sChm){
- if(this._oCtx._delivery == "msdn"){
- isALink = true;
- } else if(this._oCtx._delivery == "psdk" && sDelivery == "psdk"){
- isALink = true;
- } else if(this._oCtx._delivery == "dx"){
- // All PermTargs link to the web.
- }
- }
- } else {
- oDest._hxslink = "useless";
- isHXSLink = true;
- }
-
- if(isALink){
- // generate an ALINK if we're in CHM mode and are
- // linking to something in another CHM
- oDest._alink = oSrc.rid;
- // javascript: doesn't like ids that contain colons. Convert to "__"
- oDest._alinkproxy = oSrc.rid.replace(":","__");
- oDest.SetHREF("JavaScript:" + oDest._alinkproxy + ".Click()");
- oDest._leave = "chm";
- }
-
- break;
- case "hxs":
- if (bHTTP)
- {
- oDest._leave = "ms";
- }
- else
- {
- if(sPerm){
- if(sChm){
- if(this._oCtx._delivery == "msdn"){
- // peterril: code that generates the mshelp:link will be defered until
- // render time.
- oDest._hxslink = "useless"; // just a placeholding to indicate that this
- // is an hxs link.
- isHXSLink = true;
- } else if(this._oCtx._delivery == "psdk" && sDelivery == "psdk"){
- oDest._hxslink = "useless";
- isHXSLink = true;
- } else if(this._oCtx._delivery == "dx"){
- // All PermTargs link to the web.
- }
- }
- } else {
- oDest._hxslink = "useless";
- isHXSLink = true;
- }
- }
-
- break;
- default:
- break;
- }
- }
-
- if(!isHXSLink && !isALink && (sMedia == "chm" || sMedia == "hxs")){
- var sDomain = this._oCtx._domain;
- var sHREF = oDest.GetHREF();
-
- if(sDomain && sDomain != "null"){
- if(!bHTTP){
- // Need to prepend the domain onto the path for correct linking.
- sHREF = sDomain + sHREF;
- oDest.SetHREF(sHREF);
- return true;
- }
- }
- }
-
- // Prevent recursion. if this is a self-reference we're done.
- // Don't calculate a path relative to yourself!!
- if (goTD.IsSelf(oSrc.rid))
- {
- return true;
- }
-
- if (bHTTP)
- {
- if (sMedia && (sMedia == 'chm') && sChm && (sChm == 'other'))
- { // Linking to another CHM
- oDest._leave = "chm";
- return true;
- }
- else if (sMedia && (sMedia == 'chm') && !sChm)
- { // Linking to another CHM
- oDest._leave = "ms";
- return true;
- }
- else
- {
- // Search list of Microsoft sites
- var bFound = false;
- var len = gaMSSiteREs.length;
- for ( var i=0; i<len; i++ )
- {
- if ( gaMSSiteREs[i].test(sTargHREF) )
- { // Linking to a non-MS site
- bFound = true;
- break;
- }
- }
- if ( ! bFound )
- { // Linking to a non-MS site
- oDest._leave = "ms";
- return true;
- }
- }
- }
-
- if (!goTD.Ensure())
- {
- this._error = goTD.GetError();
- return false;
- }
-
-
- if (sMedia && (sMedia == 'chm'))
- {
- var sHREF;
- // BUGBUG: htm extension is hard-coded in the CHM case.
- sHREF = MakeRelative(goTD.GetHREF(), oDest.GetHREF());
- if (!sHREF)
- {
- this._error = "VROOT2Relative failure.";
- return false;
- }
- else
- {
- //Only change the target path if its extension is in the map.
- var sExt = JustExt(sHREF);
- if (sExt)
- {
- var sNewExt = gaExtMap[sExt];
- if (sNewExt)
- {
- sHREF = ChangeExt(sHREF, sNewExt);
- }
- }
-
- oDest.SetHREF(sHREF);
-
- return true;
- }
- }
-
- return true;
-
- }
-
- // extract the href from the target
- CLookup.prototype.ExtractHREF = function(oSrc, oDest, oCacheItem)
- {
- var oTNode = oCacheItem._targetNode;
- var sDevLang = oSrc.devlang;
- var sPageType = oCacheItem._type;
-
- var oHREF = null, oNodes = null, sHREF = null;
-
- //markda: special procesing if we are using targets V2
- if ( this._oCtx.UseTargetsV2() )
- {
- if ( oNodes = this.EnsureIONodes( oSrc, oDest, oCacheItem ) )
- {
- if (oNodes.length == 1)
- {
- sHREF = oNodes[0].getAttribute("href");
- if ( sHREF )
- {
- oDest.SetHREF( sHREF );
- }
- else
- {
- this._error = "@href missing from target subnode.";
- return false;
- }
- }
- else
- {
- this._error = "ambiguous xref; must specify @iid, @oid, or @primary.";
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- else
- {
- //markda: end
- if (sDevLang == "") // generic topic
- {
- if (!(oDest.SetHREF(oTNode.getAttribute("href"))))
- {
- this._error = "@href missing on generic topic targ node.";
- return false;
- }
- }
-
- // check for @href on dlang <dlang value="scr" href="..."
- else if (oHREF = oTNode.selectSingleNode("dlang[@value='" + sDevLang + "']/@href"))
- {
- oDest.SetHREF(oHREF.value);
- }
- // check @href on dlang/dp_iface || dlang/dp_object
- else if (oNodes = this.EnsureIONodes(oSrc, oDest, oCacheItem))
- {
- if (oNodes.length == 1)
- {
- if (!oDest.SetHREF(oNodes(0).getAttribute("href")))
- {
- this._error = "@href missing from target subnode.";
- return false;
- }
- }
- else
- {
- this._error = "ambiguous xref; must specify @iid, @oid, or @primary.";
- return false;
- }
- }
- // check for href on targ first
- else if (sHREF = oTNode.getAttribute("href"))
- {
- // href directly on the targ
- oDest.SetHREF(sHREF)
- }
- else
- {
- this._error = "href missing on target node";
- return false;
- }
- }
-
- if (!this.CheckFragment(oSrc, oDest, oCacheItem))
- {
- //at: Enforce authoring of valid fids.
- this._error = "unknown fragment: fid='" + oSrc.fid + "'";
- return false;
- }
-
- return true;
- }
-
- CLookup.prototype.CheckFragment = function(oSrc, oDest, oCacheItem)
- {
- if (!oSrc)
- {
- return true;
- }
-
- var sFid = oSrc.fid;
- if (sFid)
- {
- var oTNode = oCacheItem._targetNode;
-
- var oFrag = oTNode.selectSingleNode("frag[@id='" + sFid + "'][@caption]");
- if (oFrag)
- {
- oDest.SetHREF(oDest.GetHREF() + "#" + sFid);
- if (!this.HasOverridingCaption(oSrc))
- {
- oDest.SetCaption(oFrag.getAttribute("caption"));
- }
- }
- else
- {
- // BUGBUG: We can be a little more tolerant here since the page physically exists.
- //oDest._error = "Invalid fragment specifier '" + sFid + "'.";
- //at: oDest.SetHREF(oDest.GetHREF() + "#unknown_fragment");
- return false;
- }
- }
-
- return true;
- }
-
- // if the specified node refers to a namespace, cache the name
- CLookup.prototype.IsNameSpaceRef = function(oSrcNode, sKey)
- {
- this._nsinfo = new Object();
-
- if (!sKey)
- {
- sKey = "rid";
- }
-
- var sRID = oSrcNode.getAttribute(sKey);
- if (!sRID)
- {
- this._error = "unable to retrieve " + sKey + " from node."
- return false;
- }
-
- var oCacheItem = this.RetrieveCachedItem(sRID, true);
- if (!oCacheItem)
- {
- return false;
- }
-
- var oTNode = oCacheItem._targetNode;
- if (!oTNode)
- {
- return false;
- }
-
- var sType = oTNode.getAttribute("type");
- if (sType && sType == "namespace")
- {
- this._nsinfo["key"] = sRID;
- this._nsinfo["name"] = oTNode.getAttribute("name");
- return true;
- }
-
- return false;
- }
-
- // assuming the namespace has already been retrieved, return the specified attribute. only "name" is currently supported
- CLookup.prototype.GetNameSpaceInfo = function(o, sAttr)
- {
- // should never happen if IsNameSpaceRef is called first and return value is checked
- if (null == this._nsinfo || null == this._nsinfo[sAttr])
- {
- return "";
- }
-
- return this._nsinfo[sAttr];
- }
-
-
- // returns true if the ref topic applies to at least one object that has a persistent representation
- function AppliesToPersistentHTMLObject()
- {
- // peterril: commented out this condition because DHTML is defined for only the core DOM. That means that
- // all the other scripting events do not have this tech value.
- // BUGBUG: Only show this for HTML objects?
- //if (!ownerDocument.selectSingleNode("/inetsdk:topic/metadata/tech[@value='dhtml']"))
- //{
- // return false;
- //}
-
- var oObjects = ownerDocument.selectNodes("/inetsdk:topic/metadata/applies/object/@rid");
- if (!oObjects || 0 == oObjects.length)
- {
- return false;
- }
-
- for (var i = 0; i < oObjects.length; i++)
- {
- var oTNode = goLookup.RetrieveTarget(oObjects[i].value);
- if (!oTNode)
- {
- continue;
- }
- else if (oTNode.getAttribute("pn")) // BUGBUG: Assumes XML for target data
- {
- return true;
- }
- }
-
- return false;
- }
-
- // Retrieve the type of the current topic
- function GetPageType()
- {
- var oTypeAttr;
- if (oTypeAttr = ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@type"))
- {
- return (oTypeAttr.value);
- }
- else
- {
- return null;
- }
- }
-
- // Does sRID match the id of the current topic
- function IsSelfReference(sRID)
- {
- return ( (sRID == null || sRID == ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@id").value) ? true : false);
- }
-
- // map the attributes of an XML DOM Node to the properties of a JScript object
- function Node2Object(oNode, oObj, sPrefix)
- {
- if (!oNode)
- {
- return null;
- }
-
- if (!oObj)
- {
- oObj = new Object();
- }
-
- var oAttrs = oNode.attributes;
- for (var i = 0; i < oAttrs.length; i++)
- {
- var oAttr = oAttrs(i)
- oObj[(sPrefix ? sPrefix : "") + oAttr.name] = oAttr.value;
- }
-
- oObj._nodeName = oNode.nodeName;
-
- return oObj;
- }
-
- // Ensure that the criteria string contains single quotes and is surrounded by square brackets
- function NormalizeCriteria(sCriteria)
- {
- if (typeof(sCriteria) != 'string')
- {
- return "";
- }
-
- sCriteria = sCriteria.replace(/"/g, "'");
- if (!/^\[/.test(sCriteria))
- {
- sCriteria = "[" + sCriteria;
- }
-
- if (!/\]$/.test(sCriteria))
- {
- sCriteria += "]";
- }
-
- return sCriteria;
- }
-
-
- /* XREF code END */
- ]]>
-